package com.ittx.dzt.weidian.service;

import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.edi.dto.StoreOnSaleSkuDTO;
import com.ittx.dzt.sys.response.Result;
import com.ittx.dzt.weidian.handler.AbstractBaseWeidianApiHandler;
import open.constant.PlatformApiConstant;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/**
 * 商品上架
 * <p>
 * cy.sku.listing
 * 商品上下架(weidian.item.onSale) https://open.weidian.com/#/api/52
 * </p>
 *
 * @author wl_code@163.com
 * @version 1.0
 * @date 2025/4/1
 */
@Service
public class WeidianSkuListingService extends AbstractBaseWeidianApiHandler<StoreOnSaleSkuDTO> {

	@Override
	public String getLocalApiMethod() {
		return PlatformApiConstant.InboundInterface.SKU_LISTING;
	}

	@Override
	public Result<?> doProcess(PlatformApiParamDTO platformApiParamDTO, StoreOnSaleSkuDTO storeOnSaleSkuDTO) {
		Map<String, Object> params = new HashMap<>();
		// 商品id
		String[] array = storeOnSaleSkuDTO.getPlatformSpuId().split(",");
		for (String productId : array) {
			params.put("itemid", productId);
			// 1表示商品上架，2表示商品下架
			params.put("opt", "1");
			Result<?> result = this.executeWeidianApi(platformApiParamDTO.getStoreConfig(), params, platformApiParamDTO.getRequestId());
			if (result.hasError()) {
				return result;
			}
		}
		return Result.success();
	}

	@Override
	public String getWeidianMethod() {
		return "weidian.item.onSale";
	}

	@Override
	public String getWeidianApiVersion() {
		return "1.0";
	}

	@Override
	public String getWeidianApiFormat() {
		return "json";
	}
}
